<template>
  <base-breadcrumb>
    <searchData :searchData="searchArr" @search="search"></searchData>
  
    <a-card :bordered="false" style="over-flow:scroll">
        <!-- <title-name title="设计资源考察列表"></title-name> -->
      <div>
        <a-row>
          <a-col :md="24" :sm="19">
            <div class="table-operator">
              <a-row>
                <a-col :md="24" :sm="24">
                  <a-button type="primary"  @click="goAdd('add')" v-btnPermission="'ds_007_add_01'">新增设计资源考察</a-button>
                </a-col>
              </a-row>
            </div>
            <div class="pub-table-select-count">
              <a-icon type="info-circle" theme="twoTone"/>
              <span style="margin-right: 12px">
                考察总数：<span class="totalNum">{{total.total || 0 }} 个 </span> |
                待提交审核：<span class="totalNum">{{total.draftNum || 0 }} 个 </span> |
                审核中：<span class="totalNum">{{ total.submittedNum || 0}} 个 </span> |
                审核通过：<span class="totalNum">{{ total.passNum || 0}} 个 </span> |
                审核不通过：<span class="totalNum">{{ total.rejectedNum || 0 }} 个 </span>
              </span>
            </div>
            <list-table
                    ref="table"
                    size="default"
                    rowKey="id"
                    :columns="columns"
                    :request="loadData"
                    :alert="true"
                    show-size-changer
                    show-quick-jumper
                    showPagination="auto">
                    <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
              <span slot="action" slot-scope="text, record">
                <MoreButton>
                <a @click="handleSub(record,'view')" v-btnPermission="'ds_007_loo_02'">查看</a>
                <a-divider v-if="record.statusCode=='0' || record.statusCode =='3'" type="vertical" v-btnPermission="'ds_007_edi_03'"/>
                <a v-if="record.statusCode=='0' || record.statusCode =='3'" @click="handleEdit(record,'edit')" v-btnPermission="'ds_007_edi_03'">编辑</a>
                  <a-divider  v-if="record.statusCode=='1'|| record.statusCode=='2'||record.statusCode=='3'"   type="vertical" v-btnPermission="'ds_007_moi_05'"/>
                <a v-if="record.statusCode=='1' || record.statusCode=='2'||record.statusCode=='3' "  @click="handleApproveDetail(record)" v-btnPermission="'ds_007_moi_05'">审批信息</a>
                </MoreButton>
              </span>
            </list-table>
          </a-col>
        </a-row>
      </div>
    </a-card>
            <!-- 审批详情 -->
        <ApprovalDetails
            :businessId="businessId"
            :visible="visibleApprove"
            @cancel="visibleApprove = false"
            @confirm="visibleApprove = false"
        />
  </base-breadcrumb>
</template>

<script>

  import Vue from 'vue'
  import { getAttachment ,getTypesLabel} from '@/api/commons'
  import { getCompany } from '@/api/themeChoose/themeChoose'
  import { STable, Ellipsis } from '@/components'
  import { getList ,addBasic ,getListTotal ,getBasic} from '@/api/design/investigate/index'
  import ApprovalDetails from '@/components/approvalDetails'
  import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
  import OrgTreeSelect from '@/components/OrgTreeSelect'
  const columns = [
    {
      title: '序号',
      width: '65px',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '考察名称',
      dataIndex: 'name'
    },
    {
      title: '考察评级',
      width: '100px',
      dataIndex: 'surveyLevelName',
    },
    {
      title: '考察类型',
      dataIndex: 'surveyTypeName',
    },
    {
      title: '考察分公司',
      dataIndex: 'branchComName',
    },
    {
      title: '考察组长',
      dataIndex: 'surveyGroupName',
    },
    {
      title: '考察时间',
      dataIndex: 'surveyDate',
    },
    {
      title: '创建人',
      width: '100px',
      dataIndex: 'createName',
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
    },
    {
      title: '状态 ',
      width: '110px',
      dataIndex: 'statusName',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]

  const treeData = [
    {
      title: '物资公司招标单位',
      key: '0-0',
      id: '53085e2c9f1f4685801ef31994f57c49',
      children: [
        { title: '招标', key: '0-0-0', id: '59ced46f24184856997762478cc5b39a'},
        { title: '招标1', key: '0-0-1', id: '59ced46f24184856997762478cc5b39b'},
        { title: '招标2', key: '0-0-3', id: '59ced46f24184856997762478cc5b39c'},
      ],
    },
  ];
  export default {
    name:'a'+ Date.now(),
    components:{
      STable,
      ApprovalDetails
    },
    data(){
      this.columns = columns
      this.treeData = treeData
      return{
        // 查询参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          if (this.queryParam.rangeTime && !!this.queryParam.rangeTime.length) {
            this.queryParam.startDate = this.queryParam.rangeTime[0].format('YYYY-MM-DD') || void 0,
            this.queryParam.endDate = this.queryParam.rangeTime[1].format('YYYY-MM-DD') || void 0
          }
          this.queryParam.rangeTime=null
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getList(requestParameters)
            .then(res => {
              return res
            })
        },
        selectedRowKeys:'',
        selectedRows:'',
        advanced:false,
        confirmLoading:false,
        form:{},
        visible:false,
        businessId:'',
        visibleApprove:false,
        id:'',
        total:{},
        searchArr: [
          // 搜索框
          {
            name: '考察名称',
            value: 'surveyName',
            type: 'input'
          },
          {
            name: '状态',
            value: 'status',
            type: 'select',
            data:[
              {
                value: '0',
                label: '待提交审核'
              },
              {
                value: '1',
                label: '审核中'
              },
              {
                value: '2',
                label: '审核通过'
              },
              {
                value: '3',
                label: '审核不通过'
              },
            ]
          },
          {
            name: '所属单位',
            valueKey: 'searchQuery',
            type: OrgTreeSelect,
          },
          //                               {
          //   name: '分公司',
          //   valueKey: 'branchComId',
          //   type: SelectSubCompany ,

          // },
          // {
          //   name: '分公司',
          //   value: 'branchComId',
          //   type: 'select',
          //   data:[]
          // },
          {
            name: '考察类型',
            value: 'surveyTypeId',
            type: 'select',
            data:[]
          },
          {
            name: '考察时间阶段',
            value: 'rangeTime',
            type: 'dateRange'
          },
          {
            name: '考察评级',
            value: 'surveyLevelId',
            type: 'select',
            data:[]
          },
        ]
      }
    },
    computed: {
      // rowSelection() {
      //   return {
      //     selectedRowKeys: this.selectedRowKeys,
      //     selectedRows: this.selectedRows,   // 当前行所有数据
      //     onChange: this.onSelectChange
      //   }
      // }
    },
    created(){
      const userInfo = Vue.getAcloudProvider().getUserInfo()
      this.getCompanyList({orgIds:[userInfo.orgId], tagCodes:['BC']})
      this.getListTotal()
      this.getTypesLabel()
    },
    methods:{
      // 分公司
      getCompanyList(params){
        getCompany(params).then(res=>{
          let companyList = []
          res.data.forEach(item=>{
            companyList.push({
              label:item.orgName,
              value:item.orgId
            })
          })
          this.searchArr[2].data = companyList
        })
      },
      getTypesLabel(){
        // 考察类型
        getTypesLabel({type:'14'}).then(res=>{
          let list = []
          res.data.forEach(item=>{
            list.push({
              label:item.name,
              value:item.id
            })
          })
          this.searchArr[3].data = list
        })
        // 评级
        getTypesLabel({type:'13'}).then(res=>{
          let list = []
          res.data.forEach(item=>{
            list.push({
              label:item.name,
              value:item.id
            })
          })
          this.searchArr[5].data = list
        })
      },
      getListTotal(){
        getListTotal(this.queryParam).then(res=>{
          this.total=res.data
        })
      },
      toggleAdvanced() {
        this.advanced = !this.advanced
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        console.log(selectedRowKeys)
        console.log(selectedRows)
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      search(values){
        this.queryParam = values
        this.$refs.table.refresh(true)
        this.getListTotal() // 更新统计数据
      },
      handleApproveDetail(record){
        this.visibleApprove = true
        this.businessId = record.id
      },
      goAdd(type){ 
        this.$router.push({
          path:'/project/design/addInvestigate' ,
          query:{
            type:type
          }
        })
      },
      handleSub(record,type){
        this.$router.push({
          path:'/project/design/viewInvestigate',
          query:{
            id:record.id,
            type:type
          }
        })
      },
      handleEdit(record,type){
        this.$router.push({
          path:'/project/design/editInvestigate',
          query:{
            id:record.id,
            type:type
          }
        })
      },
      handleChange(){

      },
      handleChange1(){

      },
      handleOk(){
      this.visible = false
        addSubcontractors(this.form).then((res)=>{
          if(res.code=='200'){
            this.$message.success("新增成功")
          }
        })
      },
      handleCancel(){
      this.visible = false
      }
    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
</style>
